<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>三元运算符</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="app"></div>
</body>

<script>
    const app = Vue.createApp({
        data(){
            return{
                message: '好消息'
            }
        },
        methods:{
            onclickmessage(){
                this.message = this.message=='好消息'?'坏消息':'好消息'
            }
      },
        template:`<h2
        :class="message=='好消息'?'red':'black'"
        v-on:click="onclickmessage">{{message}}</h2>`
    })
    app.mount("#app")
</script>

<style>
    .red{
        color: red;
    }
    .black{
        color: #000;
    }
</style>
</html>